package com.manong.bookstore.user.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.common.utils.PageUtils;
import com.manong.common.utils.Query;

import com.manong.bookstore.user.dao.CollectDao;
import com.manong.bookstore.user.entity.CollectEntity;
import com.manong.bookstore.user.service.CollectService;


@Service("collectService")
public class CollectServiceImpl extends ServiceImpl<CollectDao, CollectEntity> implements CollectService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CollectEntity> page = this.page(
                new Query<CollectEntity>().getPage(params),
                new QueryWrapper<CollectEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CollectEntity queryByUserIdAndStoreId(String userId, String storeId) {
        QueryWrapper<CollectEntity> wrapper = new QueryWrapper<CollectEntity>().eq("user_id", userId.toString()).eq("store_id", storeId.toString());
        List<CollectEntity> result = baseMapper.selectList(wrapper);

        if(result.size() >= 1)
            return result.get(0);
        else
            return null;
    }

}